<?php

namespace App\Policies;

use App\User;
use App\OrderPay;
use Illuminate\Auth\Access\HandlesAuthorization;

class OrderPayPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view the orderPay.
     *
     * @param  \App\User  $user
     * @param  \App\OrderPay  $orderPay
     * @return mixed
     */
    public function view(User $user, OrderPay $orderPay)
    {
        //
        return $user->id===$orderPay->user_id;
    }

    /**
     * Determine whether the user can create orderPays.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        return true;
    }

    /**
     * Determine whether the user can update the orderPay.
     *
     * @param  \App\User  $user
     * @param  \App\OrderPay  $orderPay
     * @return mixed
     */
    public function update(User $user, OrderPay $orderPay)
    {
        return $user->id===$orderPay->user_id;
    }

    /**
     * Determine whether the user can delete the orderPay.
     *
     * @param  \App\User  $user
     * @param  \App\OrderPay  $orderPay
     * @return mixed
     */
    public function delete(User $user, OrderPay $orderPay)
    {
        return $user->id===$orderPay->user_id;
    }

    /**
     * 取消订单
     */
    public  function candleOrder(User $user,OrderPay $orderPay){
        if (!$orderPay->paid_at&&$user->id==$orderPay->user_id){
            return true;
        }
    }
    /**
     * 退款
     */
    public function refundOrder(User $user,OrderPay $orderPay){//退款操作 待接单的时候
        if($orderPay->ship_status==OrderPay::SHIP_STATUS_SURE_ORDER&&$user->id==$orderPay->user_id&&$orderPay->refund_status!=OrderPay::REFUND_STATUS_APPLIED){
            return true;
        }
    }
    /**
     * 确认订单
     */
    public function sureOrder(User $user,OrderPay $orderPay){
        if($orderPay->ship_status==OrderPay::SHIP_STATUS_DELIVERED&&$user->id==$orderPay->user_id){
            return true;
        }
    }

    /**
     * @param User $user
     * @param OrderPay $orderPay
     * @return bool
     * 查看物流
     */
    public function viewExpress(User $user,OrderPay $orderPay){
        if($orderPay->ship_status==OrderPay::SHIP_STATUS_RECEIVED&&$user->id==$orderPay->user_id){
            return true;
        }
    }
}
